# -*-coding:utf-8 -*-
# create by yuc
# 2018-06

import os,configparser

ROOT_PATH_S = os.path.dirname(os.path.realpath(__file__))
ROOT_PATH = os.sep.join(ROOT_PATH_S.split(os.sep)[0:-1]) + os.sep  

COOKIE_NAME = os.path.join(ROOT_PATH,"cookie.ck")

HTTP_HEADER = {
        "Accept": "application/json",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
        "Pragma": "no-cache",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
        
        }


#########################################xiapibuy功能url###############################################################
#商品分类列表
str_url_category = 'https://xiapi.xiapibuy.com/api/v2/fe_category/get_tree'
#指定商品类别的店铺id列表
str_url_cat_shop_list = 'https://xiapi.xiapibuy.com/api/v2/search_items/?by=relevancy&fe_categoryids={}&limit=50&newest={}&order=desc&page_type=search&version=2'
#获取指定店铺id的粉丝用户列表
str_url_shop_follower_list = 'https://xiapi.xiapibuy.com/shop/{}/followers/?offset={}&limit=20&offset_of_offset=0&__classic__=1'
#执行关注
str_url_run_follow = 'https://xiapi.xiapibuy.com/buyer/follow/shop/{}/'
#执行取消关注
str_url_run_unfollow = 'https://xiapi.xiapibuy.com/buyer/unfollow/shop/{}/'
#根据用户名获取当前id
str_url_username_id = 'https://xiapi.xiapibuy.com/api/v2/shop/get?username={}'
#根据用户店铺id获取店铺关注列表
str_url_shop_following_list = 'https://xiapi.xiapibuy.com/shop/{}/following/?offset={}&limit=20&offset_of_offset=0&__classic__=1'



def config_read(str_config_name):
    config = configparser.ConfigParser()
    config.read('config.ini', 'utf-8')
    configs = config.items(str_config_name)
    configs = dict(configs)
    return configs

def config_read_type(str_ini_type):
    config = configparser.ConfigParser()
    config.read('config.ini', 'utf-8')
    sections = config.sections()
    ret_sections = []
    for item in sections:
        if item.find(str_ini_type) != -1:
            ret_sections.append(item)
    return ret_sections

def three_compare(buf1,buf2,buf3):
    #print (len(buf1),len(buf2),len(buf3))
    if len(buf1) == len(buf2) == len(buf3):
        return True
    else:
        return False

'''
def get_hiddenvalue(url):
    res = requests.get(url,verify=False,)
    content = res.text
    
    p1 = re.compile('<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.+)" />')
    VIEWSTATE =p1.findall(content)
    EVENTVALIDATION =re.findall('input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />', content)
    #print (VIEWSTATE,EVENTVALIDATION)
    return VIEWSTATE[0],EVENTVALIDATION[0]
'''